#ifndef _mh_mcu_
#define _mh_mcu_

#include <cstring>
#include <fstream>
#include "external_board.h"
#include "igslib_iutil.h"

// include ikv library &  DragonBallRce Protocol
#include "igslib_iutil.h"
#include "optiga_host.h"
#include "optiga_curve.h"
#include "optiga.h"
#include "protocol_DragonBall.h"

#define XFER_TX_LEN 1026
#define XFER_RX_LEN 20
#define DATA_LOAD_MAX	1024
#define APPADDRESS  0x08004100

namespace igslib
{
     class ikv:public IProtectUnit
    {
        protected:
            ISpi* m01spi;
            optiga_session  auth_session;
            State ikv_state;
            int ROMaddr;
        public:
            ikv()
            {
                m01spi = nullptr;
                ikv_state= State::Idle;
                ROMaddr=0;
            }
            void SetSPI(ISpi* value) { m01spi = value; }
            bool SendRequest(const std::string&,const std::vector<char>&) ;
            std::vector<char> Withdraw() ;
            void Deposit(const std::vector<char>&) ;
            bool Authenticate() ;
            IProtectUnit::State GetState() ;
            void ProtectEnable();
			void Seal();
    };
	
	
	
	class mh_mcu:public CSerialExternalBoard
    {
        protected:
            unsigned char Uart_TxBuf[XFER_TX_LEN];
            unsigned char Uart_RxBuf[XFER_RX_LEN];
            int wait_ack(int);
            unsigned char u8checksum(char*,int);
        public:
            mh_mcu();
			~mh_mcu();
            virtual std::string GetSourceVersion();
            virtual std::string GetVersion();
            virtual int Upgrade();
			virtual void ImportRawData(char* data, int len);
    };

};

#endif
